﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using TCKQKL.FrontEnd.DataModel;
using TCKQKL.Service.LookupClient;
using TCKQKL.FrontEnd.Config;

namespace TCKQKL.FrontEnd.Web
{
    public partial class _Default : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            string userid = HttpContext.Current.User.Identity.Name;

            if (string.IsNullOrEmpty(userid))
            {
                HttpCookie authcookie = Request.Cookies[FormsAuthentication.FormsCookieName];
                if (authcookie == null)
                {
                    FormsAuthentication.SignOut();
                    Response.Redirect(Settings.URL_PAGE_LOGIN);
                }
                FormsAuthenticationTicket ticket = (FormsAuthenticationTicket)FormsAuthentication.Decrypt(authcookie.Value);
                userid = ticket.Name;
            }

            LSClient client = new LSClient();
            if (client.getAccountData(HttpContext.Current.User.Identity.Name) != null)
            {
                InvestorDataProfileUI investor = client.getAccountProfileData(client.getAccountData(HttpContext.Current.User.Identity.Name).investorId);
                client.Close();
                if (investor != null)
                {
                    if (Page.Master != null)
                    {
                        Label fullName = (Label)Page.Master.FindControl("lblFullName");
                        Label accountNo = (Label)Page.Master.FindControl("lblAccountNo");
                        Label phone = (Label)Page.Master.FindControl("lblPhone");
                        Label address = (Label)Page.Master.FindControl("lblAddress");
                        fullName.Text = investor.name;
                        accountNo.Text = investor.accountNo;
                        address.Text = investor.address;
                        phone.Text = investor.phone;
                    }
                }
            }
            this.MarketSummary1.marketName = "HOSE";
            this.MarketSummary2.marketName = "HASTC";
        }
    }
}
